package com.erp.gather.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.erp.gather.domain.bo.ErpAutoCollectProductTemporaryBo;
import com.erp.gather.domain.vo.ErpAutoCollectProductTemporaryVo;
import com.erp.gather.service.IErpAutoCollectProductTemporaryService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;

import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.common.core.utils.oldUtils.StringUtils;

import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 自动化公共产品临时
 *
 * @author erp
 * @date 2024-01-10
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/gather/autoCollectProductTemporary")
public class ErpAutoCollectProductTemporaryController extends BaseController {

    private final IErpAutoCollectProductTemporaryService iErpAutoCollectProductTemporaryService;

    /**
     * 查询自动化公共产品临时列表
     */
    @SaCheckPermission("gather:autoCollectProductTemporary:list")
    @GetMapping("/list")
    public TableDataInfo<ErpAutoCollectProductTemporaryVo> list(ErpAutoCollectProductTemporaryBo bo, PageQuery pageQuery) {
        return iErpAutoCollectProductTemporaryService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取自动化公共产品临时详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("gather:autoCollectProductTemporary:query")
    @GetMapping("/{id}")
    public R<ErpAutoCollectProductTemporaryVo> getInfo(@NotNull(message = "主键不能为空")
                                                       @PathVariable Long id) {
        return R.ok(iErpAutoCollectProductTemporaryService.queryById(id));
    }

    /**
     * 新增自动化公共产品临时
     */
    @SaCheckPermission("gather:autoCollectProductTemporary:add")
    @Log(title = "自动化公共产品临时", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpAutoCollectProductTemporaryBo bo) {
        return toAjax(iErpAutoCollectProductTemporaryService.insertByBo(bo));
    }

    /**
     * 修改自动化公共产品临时
     */
    @SaCheckPermission("gather:autoCollectProductTemporary:edit")
    @Log(title = "自动化公共产品临时", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpAutoCollectProductTemporaryBo bo) {
        return toAjax(iErpAutoCollectProductTemporaryService.updateByBo(bo));
    }

    /**
     * 删除自动化公共产品临时
     *
     * @param ids 主键串
     */
    @SaCheckPermission("gather:autoCollectProductTemporary:remove")
    @Log(title = "自动化公共产品临时", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpAutoCollectProductTemporaryService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 初始化库
     */
    @GetMapping("/initializeLibrary")
    public R<Object> initializeLibrary(String categoryId) {
        return iErpAutoCollectProductTemporaryService.initializeLibrary(categoryId);
    }

}
